﻿using System.Collections.Generic;

namespace CodedUITestExtensions.Tree
{
    /// <summary>
    /// Tree node list.
    /// </summary>
    public class TreeNodeList : List<TreeNode>
    {
        private readonly TreeNode _parent;

        /// <summary>
        ///Initializes a new instance of the <see cref="T:CodedUITestExtensions.Tree.TreeNodeList"/> class.
        /// </summary>
        /// <param name="parent">Parent node for tree node list.</param>
        public TreeNodeList(TreeNode parent)
        {
            _parent = parent;
        } 

        /// <summary>
        /// Adds new node with given value to list.
        /// </summary>
        /// <param name="value">Added tree node value.</param>
        /// <returns>Added to list tree node.</returns>
        public TreeNode Add(string value)
        {
            var node = new TreeNode(value, _parent);
            base.Add(node);
            return node;
        }

        /// <summary>
        /// Adds new node to list.
        /// </summary>
        /// <param name="node">Node to add.</param>
        /// <returns>Added to list tree node.</returns>
        public new TreeNode Add(TreeNode node)
        {
            node.Parent = _parent;
            base.Add(node);
            return node;
        }
    }

}
